package org.sdp.pearproject.service.impl;


import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.sdp.pearproject.dto.request.*;
import org.sdp.pearproject.dto.response.*;
import org.sdp.pearproject.dao.domain.*;
import org.sdp.pearproject.service.*;
import org.sdp.pearproject.service.custom.*;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

/**
 * @ClassName: DepartmentServiceImpl
 * @Description:
 * @Author: SDP
 * @Date: 2022-07-15
 * @Version: 1.0
 * Table: pear_department
 * Comment:
 * 部门表
 */
@Service
public class DepartmentServiceImpl extends DepartmentServiceCustomImpl implements DepartmentService {

    static {
        beanClassNameMap.put("department", "departmentServiceImpl");
        listMethodNameMap.put("department", "listDepartment");
        listMethodParameterClassNameMap.put("department", "DepartmentQueryRequest");
        updateMethodNameMap.put("department", "updateDepartment");
        updateMethodParameterClassNameMap.put("department", "DepartmentUpdateRequest");
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer addDepartment(DepartmentAddRequest request) throws Exception {
        super.fixRequest("department", "add", request);
        return super.addDepartment(request);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer updateDepartment(DepartmentUpdateRequest request) throws Exception {
        Department record = null;
        record = departmentMapper.selectByPrimaryKey(request.getId());
        super.fixRequest("department", "update", request, record);
        return super.updateDepartment(request);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer deleteDepartment(DepartmentDeleteRequest request) throws Exception {
        if (needCheckDeleteList(request)) {
            List<Department> list = null;
            DepartmentExample example = new DepartmentExample();
            example.createCriteria().andIdIn(request.getIdList());
            list = departmentMapper.selectByExample(example);
            fixRequest("department", "delete", request, list);
        } else {
            fixRequest("department", "delete", request);
        }
        return super.deleteDepartment(request);
    }

    @Override
    public DepartmentQueryResponse queryDepartment(DepartmentQueryRequest request) throws Exception {
        super.checkNonNull(request.getId(), "id");
        DepartmentQueryResponse result = super.queryDepartment(request);
        checkResult("department", "query", request, result);
        return result;
    }

    @Override
    public List<DepartmentQueryResponse> listDepartment(DepartmentQueryRequest request) throws Exception {
        List<DepartmentQueryResponse> list = super.listDepartment(request);
        checkResult("department", "list", request, list);
        return list;
    }

    @Override
    public Integer countDepartment(DepartmentQueryRequest request) throws Exception {
        clearPageInfo(request);
        super.fixRequest("department", "count", request);
        return super.countDepartment(request);
    }

    @Override
    public BaseStatResponse statDepartment(DepartmentQueryRequest request) throws Exception {
        clearPageInfo(request);
        super.fixRequest("department", "stat", request);
        return super.statDepartment(request);
    }

}
